package main

import (
	"encoding/json"
	"fmt"
)

type Person struct {
	Name string `json:"name"`
	Age  int    `json:"age"`
}

func main() {
	p := Person{Name: "huanfion", Age: 30}

	marshal, err := json.Marshal(p)
	if err != nil {
		fmt.Printf("error: %s\n", err.Error())
	} else {
		fmt.Printf("value:%s \n", marshal)
	}
	//json-->结构体
	p1 := Person{}
	err = json.Unmarshal(marshal, &p1)
	if err != nil {
		fmt.Printf("error: %s\n", err.Error())
		return
	} else {
		fmt.Printf("%v \n", p1)
	}
}
